package com.pb.b2b.model;

import java.math.BigDecimal;
import java.util.Date;
import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import org.hibernate.annotations.Type;

import com.pb.b2b.model.enums.Status;

@Entity
@Table(name = "PRODUCT")
public class Product {

	private Long id;
	private BigDecimal price;
	private BigDecimal tax;
	private Status status;
	private int rowNumber;
	private boolean deleted;
	private Date dateAdded;
	private Date dateModified;
	private Set<Category> categories = new HashSet<Category>(0);
	private Set<ProductLanguage> productLanguages = new HashSet<ProductLanguage>(0);
	private Set<ProductImage> productImages = new HashSet<ProductImage>(0);
	private Mark mark;

	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	@Column(name = "ID", nullable = false, unique = true)
	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	@Column(name = "PRICE", nullable = false)
	public BigDecimal getPrice() {
		return price;
	}

	public void setPrice(BigDecimal price) {
		this.price = price;
	}

	@Column(name = "TAX", nullable = false)
	public BigDecimal getTax() {
		return tax;
	}

	public void setTax(BigDecimal tax) {
		this.tax = tax;
	}

	@Column(name = "STATUS", nullable = false)
	public Status getStatus() {
		return status;
	}

	public void setStatus(Status status) {
		this.status = status;
	}

	@Column(name = "ROW_NUMBER")
	public int getRowNumber() {
		return rowNumber;
	}

	public void setRowNumber(int rowNumber) {
		this.rowNumber = rowNumber;
	}

	@Column(name = "DELETED", nullable = false)
	@Type(type = "org.hibernate.type.BooleanType")
	public boolean isDeleted() {
		return deleted;
	}

	public void setDeleted(boolean deleted) {
		this.deleted = deleted;
	}

	@Column(name = "DATE_ADDED", nullable = false)
	public final Date getDateAdded() {
		return dateAdded;
	}

	public final void setDateAdded(Date dateAdded) {
		this.dateAdded = dateAdded;
	}

	@Column(name = "DATE_MODIFIED", nullable = false)
	public final Date getDateModified() {
		return dateModified;
	}

	public final void setDateModified(Date dateModified) {
		this.dateModified = dateModified;
	}

	@ManyToMany(fetch = FetchType.LAZY, cascade = CascadeType.ALL)
	@JoinTable(name = "PRODUCT_CATEGORY", joinColumns = { @JoinColumn(name = "PRODUCT_ID", nullable = false, updatable = false) }, inverseJoinColumns = { @JoinColumn(name = "CATEGORY_ID", nullable = false, updatable = false) })
	public Set<Category> getCategories() {
		return categories;
	}

	public void setCategories(Set<Category> categories) {
		this.categories = categories;
	}

	@OneToMany(fetch = FetchType.LAZY, mappedBy = "product")
	public Set<ProductLanguage> getProductLanguages() {
		return productLanguages;
	}

	public void setProductLanguages(Set<ProductLanguage> productLanguages) {
		this.productLanguages = productLanguages;
	}

	@OneToMany(fetch = FetchType.LAZY, cascade = CascadeType.ALL, mappedBy = "product")
	public Set<ProductImage> getProductImages() {
		return productImages;
	}

	public void setProductImages(Set<ProductImage> productImages) {
		this.productImages = productImages;
	}

	@ManyToOne(fetch = FetchType.LAZY)
	public final Mark getMark() {
		return mark;
	}

	public final void setMark(Mark mark) {
		this.mark = mark;
	}

}
